<!DOCTYPE html>
<html lang="en">
<head>
    <script src="http://apps.bdimg.com/libs/jquery/2.1.4/jquery.min.js"></script>
    <meta charset="UTF-8">
    <title>订单</title>
    <style>
        div{
            border: 1px solid silver;
        }
        #frame{
            width: 700px;
            height: auto;
        }
        #bottom{
            width: 700px;

        }
        #good{
            width: 700px;
            height: auto;
        }
    </style>
</head>
<body>
  <div id="frame" class="frame">
        <div id="adress" class="frame1">
            <span id="span1"></span>
            <span id="span2"></span>
            <select id="select">
            </select>
        </div>
        <div id="good" class="frame1"></div>
        </div>
        <div id="bottom" class="bottom">
            <label for="num">件数：</label>
            <span id="num"></span>
            <label for="total">合计：</label>
            <span id="total"></span>
            <input id="button" name="button" value="提交订单" type="button" onclick="button"/>
        </div>
  </div>
</body>
<script>
    window.onload=function () {
        $.ajax({
                url:"/foraging/ljh/order/getAddress",
                type:"get",
                dataType:"json",
                success:function (result) {
                  var span1 = result.userName;
                  var span2 = result.phone;
                  $("#span1").html(span1);
                  $("#span2").html(span2);
                   $.each(result.adress,function (index,value) {
                       var option = $("<option></option>");
                       option.html(value);
                       var select = $("#select");
                       select.append(option);
                   })
                }
        });
        $.ajax({
            url:"/foraging/ljh/order/getGoodMessage",
            type:"get",
            dateType:"json",
            success:function (result) {
                var div = $("#good");
                var total = 0;
                var num = 0;
                $.each(result,function (index,good) {


                    var div1 = $("<div></div>");
                    div.append(div1);
                    var div2 = $("<div></div>");
                    var div3 = $("<div></div>");
                    div1.css({
                        "width":"700px",
                        "height":"200px",
                        "float":"left"
                    });
                    div2.css({
                        "width":"200px",
                        "height":"200px",
                        "float":"left"
                    });
                    div3.css({
                        "width":"496px",
                        "height":"200px",
                        "float":"left"
                    });
                    div1.append(div2);
                    div1.append(div3);

                    var p1 =$("<p></p>");
                    var p2 =$("<p></p>");
                    var p3 =$("<p></p>");
                    var p4 =$("<p></p>");
                    var p1_value = good.goodsattribute;
                    var p2_value = good.goodsdescription;
                    var p3_value = good.price;
                    var p4_value = good.count;
                    p1.html("产品参数："+p1_value);
                    p2.html("产品详情："+p2_value);
                    p4.html("购买数量："+p4_value);
                    p3.html("产品价格："+p3_value*p4_value);
                    p3.html("产品价格："+good.detailTotalPrice+"￥  以优惠："+p3_value*p4_value - good.detailTotalPrice+"￥");
                    total = total+good.detailTotalPrice;
                    total = total+p3_value*p4_value;
                    num =num+p4_value;
                    var img = $("<img/>");
                    img.attr("src","/foraging/"+good.categoryimg);
                    img.css({
                        "width":"200px",
                        "height":"200px"
                    });
                    div2.append(img);
                    div3.append(p1);
                    div3.append(p3);
                    div3.append(p4);
                    div3.append(p2);
                })
                $("#total").html(total);
                $("#num").html(num);
            }
        })

        $("input[type='button']").click(function(){
            alert("点击提交");
            $.ajax({
                url:"/foraging/ljh/order/setOrder",
                type:"get",
                dataType:"json",
                data:{"select":$("#select").val()},
                success:{
                }
            });
            window.location.href="/foraging/ljh/order/topay";
        })


        }
</script>
</html>